package com.example.service;

import com.example.demo.dao.ESQuestionDao;
import com.example.demo.pojo.SearchQuestion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;


/**
 * Author by admin, Email xx@xx.com, Date on 2020/5/29.
 * PS: Not easy to write code, please indicate.
 * @author admin
 */

@Service
public class ESQuestionService {
    @Autowired
    ESQuestionDao esQuestionDao;

    @PostMapping
    public void save(SearchQuestion question){
        esQuestionDao.save(question);
    }

    public Page<SearchQuestion> findBykey(String key, int page, int size) {
        Pageable pageable = PageRequest.of(page - 1, size);
        return esQuestionDao.findByTitleLike(key, key, pageable);
    }
}
